const utils = require("../../utils/utils");
//获取应用实例
const app = getApp()
// pages/user/user.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    balance:'0.00',
    mobile:'',
    firstOpen:0,
    face:'',
    nickName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getIndex();
  },
  loginUSER(){
    wx.navigateTo({
      url: '/pages/my/login/login',
    })
  },
  getIndex(){
    var that = this;
    app.get_local('AccToken').then(res => {
      if(utils.is_define(res)){
        utils.request('user/userInfo',{}, function (res) {
          if(res.data.code==200){
            that.setData({
              balance: res.data.data.userBalance?utils.returnFloat(res.data.data.userBalance):'0.00',
              mobile:res.data.data.tel,
              nickName:res.data.data.nickName,
              face:res.data.data.face,
              qrCode:res.data.data.qrCode||'',
              uid:res.data.data.uid,
              birthday:res.data.data.birthday
            })
          }else{
            utils.toast(res.data.msg)
          }
        })
      }
    })
  },
  gotoQrcode(){
    var img = this.data.face;
    var nickName = this.data.nickName;
    var mobile = this.data.mobile;
    wx.navigateTo({
      url: '/pages/my/userInfomation/userInfomation?face='+img+'&nickName='+nickName+'&mobile='+mobile+'&birthday='+this.data.birthday,
    })
  },
  goUrl(e){
    // wx.navigateToMiniProgram({
    //     appId: 'wx5b97b0686831c076', //金山文档小程序id
    //     path: 'pages/thirdPartyAuth/thirdPartyAuth?appId=AK20221114XQOCJZ&scope=access_personal_files,download_personal_files',
    //     success(res) {
    //         console.log(res)
    //       // 打开成功
    //     }
    //   })
    var that = this;
    app.get_local('AccToken').then(res => {
      if(utils.is_define(res)){
        var url = e.currentTarget.dataset.url;
        if(!utils.is_define(url)){
            utils.toast("装修中，敬请期待")
            return false;
        }
        if(url=='/pages/my/bindMobile/bindMobile'){
          if(utils.is_define(that.data.mobile)){
            wx.navigateTo({
                url: '/pages/my/userInfomation/userInfomation?face='+that.data.face+'&nickName='+that.data.nickName+'&mobile='+that.data.mobile,
              })
          }else{
            wx.navigateTo({
              url:url,
            })
          }
        }else{
          wx.navigateTo({
            url:url,
          })
        }
      }else{
        wx.navigateTo({
          url: '/pages/my/login/login',
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(this.data.firstOpen==1){
      this.getIndex()
    }else{
      this.setData({
        firstOpen:1
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})